<template>
    <div>
        <div class="po" @click="login()">我有账号，<b>去登录</b></div>
        <div class="login">
            <div>
                <h1>请注册！</h1>
            </div>
            <div class="username item">
                <label>
                    用户名：<input type="text" v-model.trim="form.username" />
                </label>
            </div>
            <div class="email item">
                <label>
                    邮箱：<input type="email" v-model.trim="form.email" />
                </label>
            </div>
            <div class="password item">
                <label>
                    密码：<input type="password" v-model.trim="form.password" />
                </label>
            </div>
            <div class="tel item">
                <label>
                    手机号：<input type="text" v-model.trim="form.tel" />
                </label>
            </div>
            <div class="handle">
                <button @click="submit()" class="submit">注册</button>
            </div>
        </div>
    </div>
</template>

<script>
import { addPro } from "@/api/request";
export default {
    created() {
        console.log(this.$route);
    },
    data() {
        return {
            form: {
                username: "",
                email: "",
                password: "",
                tel: "",
            },
        };
    },
    methods: {
        login() {
            this.$router.go(-1)
        },  
        submit() {
            addPro("/register", this.form).then((res) => {
                let { data } = res;
                console.log(data);
                if (data.code == 200) {
                    this.$router.push("/login");
                    // this.$router.replace("/login")
                    // this.$router.go(-1)
                }
            });
        },
    },
};
</script>

<style lang="scss" scoped>
.po{
    position: fixed;
    top: 0;
    height: 0.5rem;
    background-color:rgb(6, 193, 176) ;
    color: #fff;
    // width: 1.5rem;
    padding: .1rem;
    text-align: center;
    line-height: .5rem;
}
.login {
    // transform: translate(0, 50%);
    width: 80%;
    margin: 50% auto;
    // border: 1px solid #000;
    h1 {
        text-align: center;
        color: rgb(6, 193, 176);
    }
    .item label {
        // width: 100%;
        justify-content: space-between;
        display: flex;
        font-size: 0.4rem;
        align-items: center;
        input {
            width: 60%;
            margin: 0.18rem 0.15rem;
            &.focus {
                outline-style: none;
                border: 1px solid rgb(6, 193, 176);
            }
        }
    }
    .handle {
        margin-top: 0.2rem;
        font-size: 0.4rem;

        .submit {
            border-radius: 0.4rem;
            border: none;
            color: #fff;
            width: 1.5rem;
            height: 1rem;
            background-color: rgb(6, 193, 176);
        }
        a {
            color: rgb(6, 193, 176);
        }
    }
}
</style>
